package com.xc.service.impl;

import com.xc.dto.ResultDTO;
import com.xc.dto.ShoppingDTO;
import com.xc.entity.CourseEntity;
import com.xc.entity.ShoppingEntity;
import com.xc.entity.WebShoppingEntity;
import com.xc.mapper.CourseMapper;
import com.xc.mapper.ShoppingMapper;
import com.xc.service.ShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

@Service
public class ShoppingServiceImpl implements ShoppingService {
    @Autowired
    private ShoppingMapper shoppingMapper;


    @Override
    public ResultDTO add(WebShoppingEntity webShoppingEntity) {
        Assert.notNull(webShoppingEntity.getUserId(),"学生ID不能为空");
        Assert.notNull(webShoppingEntity.getCourseId(),"课程ID不能为空");
        return ResultDTO.builder()
                .code(0)
                .count(shoppingMapper.add(webShoppingEntity))
                .data(null)
                .build();
    }

    @Override
    public ResultDTO update(WebShoppingEntity webShoppingEntity) {
        return ResultDTO.builder()
                .code(0)
                .count(shoppingMapper.update(webShoppingEntity))
                .data(null)
                .build();
    }

    @Override
    public ResultDTO delete(WebShoppingEntity webShoppingEntity) {
        return ResultDTO.builder()
                .code(0)
                .count(shoppingMapper.delete(webShoppingEntity))
                .data(null)
                .build();
    }

    @Override
    public ResultDTO updateEnable(WebShoppingEntity webShoppingEntity) {
        return ResultDTO.builder()
                .code(0)
                .count(shoppingMapper.updateEnable(webShoppingEntity))
                .data(null)
                .build();
    }

    @Override
    public ResultDTO findById(WebShoppingEntity webShoppingEntity) {
        return ResultDTO.builder()
                .code(0)
                .count(0)
                .data(shoppingMapper.findById(webShoppingEntity))
                .build();
    }

    @Override
    public ResultDTO findAll(WebShoppingEntity webShoppingEntity) {

        return ResultDTO.builder()
                .code(0)
                .count(shoppingMapper.count(webShoppingEntity))
                .data(shoppingMapper.findAll(webShoppingEntity))
                .build();
    }

    @Override
    public ResultDTO count(WebShoppingEntity webShoppingEntity) {
        return ResultDTO.builder()
                .code(0)
                .count(shoppingMapper.count(webShoppingEntity))
                .data(null)
                .build();
    }

    @Override
    public ResultDTO findByName(WebShoppingEntity webShoppingEntity) {
        return null;
    }

    @Override
    public ResultDTO findByCourseIdAndUserId(WebShoppingEntity webShoppingEntity) {
        return ResultDTO.builder()
                .code(0)
                .count(shoppingMapper.findByCourseIdAndUserIdCount(webShoppingEntity))
                .data(shoppingMapper.findByCourseIdAndUserId(webShoppingEntity))
                .build();
    }

    @Override
    public ResultDTO findByUserId(WebShoppingEntity webShoppingEntity) {
        return ResultDTO.builder()
                .code(0)
                .count(shoppingMapper.findCountByUserId(webShoppingEntity))
                .data(shoppingMapper.findByUserId(webShoppingEntity))
                .build();
    }
}
